package com.baizhi.enumeration;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Test01 {
    public static void main(String[] args) {
        JFrame win = new JFrame("超级玛丽");
        win.setSize(300,500);

        JPanel jpanel = new JPanel();
        win.add(jpanel);

        JButton b1 = new JButton("上");
        jpanel.add(b1);
        b1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                move(Direction.UP);
            }
        });

        JButton b2 = new JButton("下");
        jpanel.add(b2);
        b2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                move(Direction.DOWN);
            }
        });

        JButton b3 = new JButton("左");
        jpanel.add(b3);
        b3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                move(Direction.LEFT);
            }
        });


        JButton b4 = new JButton("右");
        jpanel.add(b4);
        b4.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                move(Direction.RIGHT);
            }
        });

        win.setLocationRelativeTo(null);
        win.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        win.setVisible(true);
    }


    //移动的方法
    public static void move(Direction d){
        switch (d){
            case UP:
                System.out.println("往上飞一下~~~");
                break;
            case DOWN:
                System.out.println("往下飞一下~~~");
                break;
            case LEFT:
                System.out.println("往左飞一下~~~");
                break;
            case RIGHT:
                System.out.println("往右边飞一下~~~");
                break;
        }
    }
}
